package com.xxwy.protocal;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.Charset;

/**
 * @author wy
 * @date 2020/3/8 23:51
 */
public class XxwyClientHandler extends SimpleChannelInboundHandler<XxwyProtocol> {
  @Override
  protected void channelRead0(ChannelHandlerContext channelHandlerContext, XxwyProtocol xxwyProtocol) throws Exception {

  }

  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    cause.printStackTrace();
    ctx.close();
  }

  @Override
  public void channelActive(ChannelHandlerContext ctx) throws Exception {
    for (int i = 0; i < 10; i++) {
      String mes = "你个大傻逼";
      byte[] bytes = mes.getBytes(Charset.forName("utf-8"));
      XxwyProtocol xxwyProtocol1 = new XxwyProtocol(bytes.length, bytes);
      ctx.writeAndFlush(xxwyProtocol1);
    }
  }
}
